#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

int subarraySum(vector<int>& nums, int k) {
    int sum = 0;
    unordered_map<int, int> hash;
    hash[0] = 1;

    int ret = 0;

    for (int i = 0; i < nums.size(); ++i)
    {
        sum += nums[i];

        if (hash.count(sum - k)) ret += hash[sum - k];

        hash[sum]++;
    }

    return ret;
}
int main()
{
    subarraySum({ 1,1,1 }, 2);
	return 0;
}